<?php
namespace common\models;

use Yii;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "storages".
 *
 * @property string $hash
 * @property string $parent_hash
 * @property string $filename
 * @property integer $size
 * @property integer $width
 * @property integer $height
 * @property string $seconds
 * @property string $mime
 * @property string $format
 * @property string $path
 * @property integer $created_at
 * @property integer $updated_at
 */
class Storage extends \yii\db\ActiveRecord
{

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'storages';
    }

    /*
     * 产生创建日期和更新日期时间戳
     */
    public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::className(),
                'createdAtAttribute' => 'created_at',
                'updatedAtAttribute' => 'updated_at'
            ]
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [
                [
                    'hash',
                    'filename',
                    'mime',
                    'format',
                    'path'
                ],
                'required'
            ],
            [
                [
                    'size',
                    'width',
                    'height',
                    'created_at',
                    'updated_at'
                ],
                'integer'
            ],
            [
                [
                    'seconds'
                ],
                'number'
            ],
            [
                [
                    'hash'
                ],
                'string',
                'max' => 32
            ],
            [
                [
                    'parent_hash',
                    'filename',
                    'mime',
                    'format',
                    'path'
                ],
                'string',
                'max' => 255
            ]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'hash' => 'Hash',
            'parent_hash' => 'Parent Hash',
            'filename' => 'Filename',
            'size' => 'Size',
            'width' => 'Width',
            'height' => 'Height',
            'seconds' => 'Seconds',
            'mime' => 'Mime',
            'format' => 'Format',
            'path' => 'Path',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At'
        ];
    }
}
